<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
  <meta charset="utf-8" />
  <title>opencpn:opencpn_user_manual:plugins:plugin_messaging</title>
<meta name="generator" content="DokuWiki"/>
<meta name="robots" content="index,follow"/>
<meta name="keywords" content="opencpn,opencpn_user_manual,plugins,plugin_messaging"/>
<link rel="search" type="application/opensearchdescription+xml" href="../lib/exe/opensearch.html" title="OpenCPN Manuals"/>
<link rel="start" href="plugin_messaging.html"/>
<link rel="contents" href="plugin_messaging.html" title="Sitemap"/>
<link rel="alternate" type="application/rss+xml" title="Recent Changes" />
<link rel="alternate" type="application/rss+xml" title="Current namespace" />
<link rel="alternate" type="text/html" title="Plain HTML" href="plugin_messaging.html"/>
<link rel="alternate" type="text/plain" title="Wiki Markup" href="plugin_messaging.html"/>
<link rel="canonical" href="http://localhost/dokuwiki/doku.php?id=opencpn:opencpn_user_manual:plugins:plugin_messaging"/>
<link rel="stylesheet" type="text/css" href="../lib/exe/css.php.t.bootstrap3.css"/>
<!--[if gte IE 9]><!-->
<script type="text/javascript">/*<![CDATA[*/var NS='opencpn:opencpn_user_manual:plugins';var JSINFO = {"id":"opencpn:opencpn_user_manual:plugins:plugin_messaging","namespace":"opencpn:opencpn_user_manual:plugins","confirm_delete":"Are you sure you want to delete this page?","doku_base":"\/dokuwiki\/","cg_rev":"","dw_version":49.5,"chrome_version":0,"hide_captcha_error":"none","ckg_dbl_click":"","ckg_canonical":0,"has_wrap":"Wrap","wrapDiv":"WRAP","wrapSpan":"wrap","ckgEdPaste":"off","rel_links":0,"isadmin":0,"isauth":0,"move_renameokay":false,"schemes":["http","https","telnet","gopher","wais","ftp","ed2k","irc","ldap"],"htmlok":0};
/*!]]>*/</script>
<script type="text/javascript" charset="utf-8" src="../lib/exe/jquery.php.t.bootstrap3.js"></script>
<script type="text/javascript" charset="utf-8" src="../lib/exe/js.php.t.bootstrap3.js"></script>
<!--<![endif]-->

    <script type="text/javascript">
    //<![CDATA[ 
    function LoadScript( url )
    {
     document.write( '<scr' + 'ipt type="text/javascript" src="..//url"><\/scr' + 'ipt>' ) ;        

    }
   function LoadScriptDefer( url )
    {
     document.write( '<scr' + 'ipt type="text/javascript" src="..//url" defer><\/scr' + 'ipt>' ) ;        

    }
//]]> 

 </script>
</head>
<body>
<div class="dokuwiki export">



<h1 class="sectionedit1" id="plugin_messaging">Plugin Messaging</h1>
<div class="level1">

<p>
Between ODraw, Watchdog and Weather_routing.
</p>

<p>
<strong>OpenCPn Draw and Watchdog</strong>
</p>

<p>
<strong>User aspects</strong>
</p>

<p>
First of all, we should see OD and WD as separate plugins. In OD you can draw geo-referenced objects (lines, points, straight lined areas and circles). WD knows when and how to sound alarms.
</p>

<p>
In OD, a graphical indication (crosshatching or shading) may be added to areas, to indicate whether these are intended to avoid (crosshatched inside) or to stay within (crosshatched outside), or whatever other meaning you want to give to those graphical indications.
</p>

<p>
In WD you can select whether (certain types of) alarms should react only for areas that are flagged (in OD) as to avoid or to stay within, or for all areas. On top of that, in WD you can indicate whether this should be done only for areas labeled in OD as active, or inactive, or both.
</p>

<p>
The WD Boundary Alarm has 4 different types:
</p>

<p>
1. Alarm when approaching an area from outside (based on distance);<br/>

2. Alarm when approaching an area from outside (based on time);<br/>

3. Alarm to indicate whether your boat is inside or outside an area (Inclusion Alarm, another type of anchor alarm);<br/>

4. Alarm to indicate whether AIS objects are present in an area.
</p>

<p>
For the first two alarms the WD uses the same terms for the boundary that OD does as well as allowing a check for the state of the boundary. The third alarm only looks at a specific boundary which is identified by the boundaries GUID. The fourth alarm specifies a boundary to check if an AIS target is inside it.
</p>

<p>
Beside the 4 types of Boundary Alarms mentioned above, WD has the following alarm functionality:
</p>

<p>
1. Alarm when approaching coastlines (Landfall Alarm; 2 types: time and distance)<br/>

2. Alarm when NMEA-data stream stops (NMEA Alarm)<br/>

3. Deadman Alarm<br/>

4. Alarm when distance to reference position exceeds a set value (Anchor Alarm)<br/>

5. Alarm when course over ground deviates more than set (Course Alarm; 3 types: only port deviation, only starboard deviation or a general deviation);<br/>

6. Alarms when speed deviates more then set (Speed Alarm; two types: overspeed for more than set maximum, and underspeed for less than set minimum).
</p>

<p>
In total there are 14 different types of alarms.
</p>

<p>
<strong>Technical aspects</strong>
</p>

<p>
WD and OD are independent plugins. OD knows about drawing geo-referenced objects, WD knows how to sound alarms. Now the two can work together by passing and receiving messages, in this case JSON messages (basically a text string of elements and values).
</p>

<p>
For the alarms, when WD needs boundary information, WD asks OD, via a message, whether a Lat/Lon is inside a boundary. WD can add further requirements asking for boundaries in a particular state and a particular type. Both the state and type are the same as what OD uses, i.e. Active/Inactive and Exclusion/Inclusion/Neither, or the inclusive “Any” (meaning any type and/or any state, not being as selective).
</p>

<p>
In OD the boundaries checked are both an OD Boundary and an OD Boundary Point with range rings showing. Boundaries and Boundary Point Range Rings are both considered boundaries. The type of boundary applies to both, but the state (active/inactive) currently only applies to Boundaries, not Boundary Points. This is because there is currently no state for a Boundary Point. This may change in future updates to the plugins for consistency.
</p>

<p>
When OD completes its check of Lat/Lon inside boundaries it replies with a single message containing the first boundary that the Lat/Lon is inside AND which matches the type and state requested. The response message contains the Name, Description, GUID, Type and State of the boundary found.
</p>

<p>
WD uses the returned message to decide whether to sound the alarm and uses some of the information in the messages that are then displayed to the user, i.e. a change in text in the watchdog window and a message box, if requested.
</p>

<p>
Messaging in OCPN is synchronous, broadcast such that every plugin that registers for messages and the main program, OpenCPN, will receive every message sent. All processing of messages is synchronous, i.e. each plugin has to process each message completely and return to OCPN (the controller) before the next plugin can process the message. For the WD/OD message stream WD sends a message to OD, OD processes the message and sends a response message to WD, WD mainline processes the response message and stores the information, then returns control to OD which then returns control to WD at the point that WD created the first message. Now WD can process the saved information from OD, and the controller, OpenCPN can process the next message.
</p>

<p>
OD messages can be used by any plugin and OCPN itself to obtain information. For the OD messaging there is a “structure” for the content of the message, specifying the source requester, the type of message (Request/Response), the message i.e. FindPointInAnyBoundary, the message id (may contain an identifier for the source requester) and then the message contents, i.e. Lat, Lon, Type, etc.
</p>

<p>
So a request looks like:
</p>

<p>
Source: “WATCHDOG_PI”<br/>

Type: “Request”<br/>

Msg: “FindPointInAnyBoundary”<br/>

MsgId: “distance”<br/>

lat: 54.0001<br/>

lon: -30.1001<br/>

BoundaryType: “Exclusion”<br/>

BoundaryState: “Active”
</p>

<p>
This message is then given a “destination”, in this case “OCPN_DRAW_PI”, when the call to the OCPN messaging process is made.
</p>

<p>
The response will look like:
</p>

<p>
Source: “OCPN_DRAW_PI”<br/>

Type: “Response”<br/>

Msg: “FindPointInAnyBoundary”<br/>

MsgId: “distance”<br/>

GUID: “62ec7520-b58f-4087-b077-ae1c581dfec1”<br/>

lat: 54.0001<br/>

lon: -30.1001<br/>

Name: “Rocks”<br/>

Description: “Good fishing”<br/>

Found: false<br/>

BoundaryObjectType: “Boundary”<br/>

BoundaryType: “Exclusion”
</p>

<p>
This message is then given a destination of the originator, in the case above “WATCHDOG_PI”, when the call to the OCPN messaging process is made.
The “destination” is used so that each recipient of the broadcast message can easily check if the message is meant for it. There is no filtering provided by OCPN messaging on this value.
</p>

<p>
Using this construct there are validation checks to make sure messages are valid to process. If they are not valid there will be error messages entered into the opencpn.log file with relevant information.
</p>

<p>
Currently this message construct is used by OD, WD, WR and the AIS processing in OCPN when it broadcasts AIS information to OCPN and the plugins. In some cases there is no response message expected, i.e. AIS just sends messages, but in others the response is important.
</p>

<p>
OD is not concerned where the message came from or why, it will just respond to message requests with what is found from inspection of OD objects. WD just wants to know if it should sound an alarm or not, so it sends message requests to OD to determine certain conditions. WR just wants to know if the current Lat/Lon is valid for further processing or not, so it sends message requests to OD to determine certain conditions. AIS just provides information on each target it is dealing with.
</p>

<p>
Now the check frequency in the WD alarm screen determines how often to check for a Lat/Lon being in a boundary. One other item which should be mentioned, is that for each boundary check based on time there are up to 11 Lat/Lon messages sent to OD, for each distance check there are up to 163 Lat/Lon messages to OD. Therefore the amount of this message traffic is something to watch.
Please note that a JSON message does not have a “structure” per se, the message consists of element/value pairs written as delimited strings. The elements can occur in any order. So “structure” in the sense used in this document really refers to required elements.
</p>

</div>
<!-- EDIT1 SECTION "Plugin Messaging" [20-] -->
<!-- no cachefile used, but created /var/www/html/dokuwiki/data/cache/9/9a97b09aa50861e90ace3af8a5dc7bb6.xhtml -->
</div>
</body>
</html>
